fix(seo): serve a real sitemap index at /sitemap.xml#36
Merged
Conversation
Follow-up to #35. generateSitemaps() served the chunked children at /sitemap/{id}.xml but Next reserves /sitemap.xml for the metadata convention and 404s the parent index there — so robots.txt and Search Console (which point at /sitemap.xml) got a 404. Drop the sitemap.ts metadata convention and hand-roll the XML instead: - /sitemap.xml (app/sitemap.xml/route.ts) -> <sitemapindex> of the children - /sitemap/{id}.xml (app/sitemap/[id]/route.ts) -> <urlset> chunk - @/lib/sitemap-shape: shared chunk math + XML serialization (hreflang alternates preserved), force-dynamic so the catalog is always complete. A real index can't be expressed with the sitemap.ts convention + a parallel route handler — they collide ("Conflicting route and metadata at /sitemap.xml"), so hand-rolling is required. Verified on a local dev server: /sitemap.xml is a well-formed sitemapindex; /sitemap/0.xml is a well-formed urlset with 29 page URLs and 435 hreflang links; bad/out-of-range ids 404 / return an empty urlset. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #35.
generateSitemaps()served the chunked children at/sitemap/{id}.xml, but Next reserves/sitemap.xmlfor thesitemap.tsmetadata convention and 404s the parent index there — androbots.txt+ Search Console point at/sitemap.xml. (A parallel route handler can't coexist with the convention: it errorsConflicting route and metadata at /sitemap.xml.)Fix
Drop the
sitemap.tsmetadata convention and hand-roll the XML:/sitemap.xml(app/sitemap.xml/route.ts) →<sitemapindex>of the children/sitemap/{id}.xml(app/sitemap/[id]/route.ts) →<urlset>chunk (1,000 URLs)@/lib/sitemap-shape→ shared chunk math + XML serialization, hreflang alternates preserved,force-dynamicso the catalog is always complete. A DB blip degrades a child to an empty<urlset>instead of a 500.Verified locally
/sitemap.xml→ well-formed<sitemapindex>./sitemap/0.xml→ well-formed<urlset>, 29 page URLs, 435 hreflang links (29×15)./sitemap/99.xml→ empty urlset (200);/sitemap/abc.xml,/sitemap/-1.xml→ 404.robots.txtstill points at the (now-working)/sitemap.xml.Will confirm the index + a couple of entity children in production after deploy.
🤖 Generated with Claude Code